﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/static/include/top3.jsp"%>
<script>document.title="导出用户";</script>
<script src="${baseURL}/static/js/jquery.easyui.min.js"></script>
<link href="${baseURL}/static/js/themes/default/easyui.css" rel="stylesheet" type="text/css" />

<style type="text/css">
<!--
table {
	margin:0;
	width:0;
	font-family:"微软雅黑";
	font-size:12px;
	color: #FFF;
	border-collapse: collapse;
}
//-->
</style>

<form name="searchForm" action="" method="get">
<input type="hidden" name="p" value="1" />
	<table style="width:98%">
		<tbody>
			<tr>
				<th><img src="${ctx}/static/images/pages/cen/rig/ico_01.png" align="absmiddle">&nbsp;导出用户</th>
			</tr>
			<tr class="tab_grey">
				<td>用户名称： 
					<input type="text" name="loginName" id="loginName" value="" size="20" class="tab_textbut" />
					单位名称： 
					<input type="text" name="unitName" id="unitName" value="" size="20" class="tab_textbut" />
					<span class="tab_text">用户类型：</span>
					<select id="roleId" name="roleId" class="tab_textbut">
						<option value="">请选择..</option>
						<c:forEach var="role" items="${roleList}">
							<option value="${role.id}">${role.roleName}</option>
						</c:forEach>
					</select>
					<input type="button" onclick="queryData();return false;" value="查询" class="tab_but" /> 
					<input type="button" class="tab_but" value="清空" onclick="clearInput();"/> 
					<input type="button" class="tab_but"  onclick="exportUsers('${ctx}');" value="导出用户" onfocus="this.blur()"/>
		    		<input type="button" class="tab_but"  onclick="setExportFlag('${ctx}');" value="设为已导出" onfocus="this.blur()"/>
				</td>
			</tr>
		</tbody>
	</table>
</form>
<script>
$("#roleId").val("${param['roleId']}");
function clearInput() {
	$("#loginName").val("");
	$("#unitName").val("");
	$("#roleId").val("");
}
</script>
<br/>
<div id="dataList" style="overflow:auto;width:98%">
<table id="dg" class="easyui-datagrid" style="width:1000px;height:400px"   
        data-options="fitColumns:true,singleSelect:true,singleSelect:false">
    <thead>   
        <tr>
        	<th data-options="field:'id',width:30, checkbox:true,align:'center'">用户ID</th>
            <th data-options="field:'userLoginname',width:200,align:'center'">用户名称</th>   
            <th data-options="field:'userUnit',width:200">单位名称</th>   
            <th data-options="field:'roleName',width:100,align:'left'">用户类型</th>
            <th data-options="field:'userUnitAdmin',width:100,align:'left'">联系人</th>
            <th data-options="field:'userContactPhone',width:150,align:'left'">联系电话</th>
            <th data-options="field:'operate',width:150,align:'center'">操作</th>
        </tr>   
    </thead>   
</table>
</div>

	<script type="text/javascript">
	
	$(function(){
		
		queryData();
		
	});
	
	var userIds = new Array();
	var pageNum = 1;
	var pageSize = 10;
	
	//表单提交查询
	function queryData(){

		var url = "${baseURL}/dataManage/queryExportUsersData";
		var params = {pageNum:pageNum, loginName:$("#loginName").val(), unitName:$("#unitName").val(), role:$("#role").val()};
		$('#dg').datagrid({
		    url:url,
		    pagination:true,
		    pageSize:pageSize,
		    rownumbers:true,
		    pageList:[20,30,40,50],
		    queryParams:params,
		    columns:[[
				{field:'id',width:30,align:'center',checkbox:true,title:'用户ID'},
		        {field:'userLoginname',width:200,align:'center',title:'用户名称'},
		        {field:'userUnit',width:200,align:'left',title:'单位名称'}, 
		        {field:'roleName',width:100,align:'left',title:'用户类型'}, 
		        {field:'userUnitAdmin',width:100,align:'left',title:'联系人'}, 
		        {field:'userContactPhone',width:150,align:'left',title:'联系电话'},
		        {field:'operate',width:150,align:'center',title:'操作', formatter: function(value,row,index){
						return "<a href='#' onclick='openViewWin(\"" + row.id + "\");return false;'>查看</a>";
					}
				}
		    ]],
		    loadFilter: function(data){
		    	data.rows = data.operationResult;
		    	data.total = data.totalCount;
		    	return data;
			},
			onCheck:function(rowIndex,rowData){
				var ishave = false;
				for (var i=0; i<userIds.length; i++){
					if (userIds[i]==rowData.id){
						ishave = true;
						break;
					}
				}
				if (!ishave){
					userIds.push(rowData.id);
				}
			},
			onUncheck:function(rowIndex,rowData){
				for (var i=0; i<userIds.length; i++){
					if (userIds[i]==rowData.id){
						userIds.splice(i, 1);
					}
				}
			},
			onSelectAll:function(rows){

				for (var j=0; j<rows.length; j++){
					var ishave = false;
					for (var i=0; i<userIds.length; i++){
						if (userIds[i]==rows[j].id){
							ishave = true;
							continue;
						}
					}
					if (!ishave){
						userIds.push(rows[j].id);
					}
					
				}
			},
			onUnselectAll:function(rows){
				for (var j=0; j<rows.length; j++){
					for (var i=0; i<userIds.length; i++){
						if (userIds[i]==rows[j].id){
							userIds.splice(i, 1);
							continue;
						}
					}
				}
			},
			onLoadSuccess:function(data){
				$.each(data.operationResult, function(i, row){
					if (userIds.toString().indexOf(row.id)>-1){
						$('#dg').datagrid("selectRow", i);
					}
				});
			}
		}); 
	}

	function openViewWin(id){
		openWin("查看详情","${baseURL}/dataManage/viewExportUser?id="+id,800,550);
	}
	
	//导出用户
	function exportUsers(){

		if(userIds.length==0){
			layer.alert("请选择要导出的用户。");
			return;
		}
		
		layer.confirm("确认导出？", function(){
			var url="${baseURL}/report/exportUser";
			$.post(url,{"idStr":userIds.toString(),},function(data){
				layer.msg(data.message, 1, 1, function(){
					if(data.result=="OK"){
						queryData();
					}
				});
			},'json');
		});	
	}
	
	/*
	 * 设置为已导出状态.
	 */
	function setExportFlag(){
		if(userIds.length==0){
			layer.alert("请选择要导出的用户。");
			return;
		}

		layer.confirm("确认执行？", function(){
			var url="${baseURL}/report/exportOverUser";
			$.post(url,{"idStr":userIds.toString(),},function(data){
				layer.msg(data.message, 1, 1, function(){
					if(data.result=="OK"){
						queryData();
					}
				});
			},'json');
		});	
	}
	</script>

<%@ include file="/static/include/bottom.jsp"%>
